﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CollegeSim.CourseScheduler.Domain.Entities;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CollegeSim.CourseScheduler.Domain.Test
{
    // Author: Ryan Redburn
    // Project: CourseScheduler
    // Date: 2/18/2014

    [TestClass]
    public class CourseTest
    {
        #region [ Property Tests]

        // Id

        [TestMethod]
        public void IdDefaultValueTest()
        {
            var course = new Course();

            Assert.AreEqual(0, course.Id);
        }

        // CRN

        [TestMethod]
        public void CrnEmptyTest()
        {
            var assert = false;

            try
            {
                var course = new Course
                {
                    CRN = "1921",
                    Subject = "CIT",
                    CourseNumber = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    IsOnline = false,
                    InstructorId = 1
                };

                course.CRN = "";
            }
            catch (ArgumentNullException)
            {
                assert = true;
            }
            finally
            {
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void CrnNullTest()
        {
            var assert = false;

            try
            {
                var course = new Course
                {
                    CRN = "1921",
                    Subject = "CIT",
                    CourseNumber = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    IsOnline = false,
                    InstructorId = 1
                };

                course.CRN = null;
            }
            catch (ArgumentNullException)
            {
                assert = true;
            }
            finally
            {
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void CrnShortLengthTest()
        {
            var assert = false;

            try
            {
                var course = new Course
                {
                    CRN = "1921",
                    Subject = "CIT",
                    CourseNumber = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    IsOnline = false,
                    InstructorId = 1
                };

                course.CRN = "105";
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void CrnExcessLengthTest()
        {
            var assert = false;

            try
            {
                var course = new Course
                {
                    CRN = "1921",
                    Subject = "CIT",
                    CourseNumber = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    IsOnline = false,
                    InstructorId = 1
                };

                course.CRN = "10005";
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                Assert.IsTrue(assert);
            }
        }

        // Subject

        [TestMethod]
        public void SubjectEmptyTest()
        {
            var assert = false;

            try
            {
                var course = new Course
                {
                    CRN = "1921",
                    Subject = "CIT",
                    CourseNumber = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    IsOnline = false,
                    InstructorId = 1
                };

                course.Subject = "";
            }
            catch (ArgumentNullException)
            {
                assert = true;
            }
            finally
            {
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void SubjectTestNull()
        {
            var assert = false;

            try
            {
                var course = new Course
                {
                    CRN = "1921",
                    Subject = "CIT",
                    CourseNumber = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    IsOnline = false,
                    InstructorId = 1
                };

                course.Subject = null;
            }
            catch (ArgumentNullException)
            {
                assert = true;
            }
            finally
            {
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void SubjectShortLengthTest()
        {
            var assert = false;

            try
            {
                var course = new Course
                {
                    CRN = "1921",
                    Subject = "CIT",
                    CourseNumber = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    IsOnline = false,
                    InstructorId = 1
                };

                course.Subject = "ci";
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void SubjectExcessLengthTest()
        {
            var assert = false;

            try
            {
                var course = new Course
                {
                    CRN = "1921",
                    Subject = "CIT",
                    CourseNumber = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    IsOnline = false,
                    InstructorId = 1
                };

                course.Subject = "citt";
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void SubjectCapitalizationTest()
        {
            var course = new Course
            {
                CRN = "1921",
                Subject = "CIT",
                CourseNumber = "190",
                Title = "JavaScript Programming",
                CreditHours = 2,
                ContactHours = 2,
                IsOnline = false,
                InstructorId = 1
            };

            course.Subject = "cit";

            Assert.AreEqual("CIT", course.Subject);
        }

        // CourseNumber

        [TestMethod]
        public void CourseNumberEmptyTest()
        {
            var assert = false;

            try
            {
                var course = new Course
                {
                    CRN = "1921",
                    Subject = "CIT",
                    CourseNumber = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    IsOnline = false,
                    InstructorId = 1
                };

                course.CourseNumber = "";
            }
            catch (ArgumentNullException)
            {
                assert = true;
            }
            finally
            {
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void CourseNumberNullTest()
        {
            var assert = false;

            try
            {
                var course = new Course
                {
                    CRN = "1921",
                    Subject = "CIT",
                    CourseNumber = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    IsOnline = false,
                    InstructorId = 1
                };

                course.CourseNumber = null;
            }
            catch (ArgumentNullException)
            {
                assert = true;
            }
            finally
            {
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void CourseShortLengthTest()
        {
            var assert = false;

            try
            {
                var course = new Course
                {
                    CRN = "1921",
                    Subject = "CIT",
                    CourseNumber = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    IsOnline = false,
                    InstructorId = 1
                };

                course.CourseNumber = "10";
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void CourseExcessLengthTest()
        {
            var assert = false;

            try
            {
                var course = new Course
                {
                    CRN = "1921",
                    Subject = "CIT",
                    CourseNumber = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    IsOnline = false,
                    InstructorId = 1
                };

                course.CourseNumber = "1005";
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                Assert.IsTrue(assert);
            }
        }

        // Title

        [TestMethod]
        public void TitleEmptyTest()
        {
            var assert = false;

            try
            {
                var course = new Course
                {
                    CRN = "1921",
                    Subject = "CIT",
                    CourseNumber = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    IsOnline = false,
                    InstructorId = 1
                };

                course.Title = "";
            }
            catch (ArgumentNullException)
            {
                assert = true;
            }
            finally
            {
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void TitleNullTest()
        {
            var assert = false;

            try
            {
                var course = new Course
                {
                    CRN = "1921",
                    Subject = "CIT",
                    CourseNumber = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    IsOnline = false,
                    InstructorId = 1
                };

                course.Title = null;
            }
            catch (ArgumentNullException)
            {
                assert = true;
            }
            finally
            {
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void TitleExcessLengthTest()
        {
            var assert = false;

            try
            {
                var course = new Course
                {
                    CRN = "1921",
                    Subject = "CIT",
                    CourseNumber = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    IsOnline = false,
                    InstructorId = 1
                };

                course.Title = "Title Title Title Title Title Title Title Title Title Title";
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                Assert.IsTrue(assert);
            }
        }

        // CreditsHours

        [TestMethod]
        public void CreditHoursBelowRangeTest()
        {
            var assert = false;

            try
            {
                var course = new Course
                {
                    CRN = "1921",
                    Subject = "CIT",
                    CourseNumber = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    IsOnline = false,
                    InstructorId = 1
                };

                course.CreditHours = 0;
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void CreditHoursAboveRangeTest()
        {
            var assert = false;

            try
            {
                var course = new Course
                {
                    CRN = "1921",
                    Subject = "CIT",
                    CourseNumber = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    IsOnline = false,
                    InstructorId = 1
                };

                course.CreditHours = 7;
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                Assert.IsTrue(assert);
            }
        }

        // ContactHours

        [TestMethod]
        public void ContactHoursBelowRangeTest()
        {
            var assert = false;

            try
            {
                var course = new Course
                {
                    CRN = "1921",
                    Subject = "CIT",
                    CourseNumber = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    IsOnline = false,
                    InstructorId = 1
                };

                course.ContactHours = 0;
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void ContactHoursAboveRangeTest()
        {
            var assert = false;

            try
            {
                var course = new Course
                {
                    CRN = "1921",
                    Subject = "CIT",
                    CourseNumber = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    IsOnline = false,
                    InstructorId = 1
                };

                course.ContactHours = 7;
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                Assert.IsTrue(assert);
            }
        }

        #endregion

        #region [ Method Tests ]

        [TestMethod]
        public void ToStringTest()
        {
            var course = new Course
            {
                CRN = "1921",
                Subject = "CIT",
                CourseNumber = "190",
                Title = "JavaScript Programming",
                CreditHours = 2,
                ContactHours = 2,
                IsOnline = false,
                InstructorId = 1
            };

            Assert.AreEqual(course.CRN + " - " + course.Subject + course.CourseNumber + " - " + course.Title, course.ToString());
        }

        #endregion
    }
}
